<template>
  <div class="talk">
    <button @click="getTalk">获取一句企鹅情话</button>
    <p>{{ talkList[number]?.title }}</p>
  </div>
</template>

<script setup lang="ts" name="LoveTalk">
import { reactive, ref } from "vue";
import axios from "axios";
import { useTalkStore } from "../store/loveTalk";
import { storeToRefs } from "pinia";

const talkStore = useTalkStore();
const { talkList, number } = storeToRefs(talkStore);
function getTalk() {
  talkStore.getATalk();
}

talkStore.$subscribe((mutate, state) => {
  console.log("talkStore里面保存的数据发生了变化", mutate, state);
  localStorage.setItem("talkList", JSON.stringify(state.talkList));
});
</script>

<style scoped>
.talk {
  background-color: orange;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}
</style>
